function patamFilter(obj){
	if(obj.indexOf("@") != -1) return obj.split("@")[0];
	return obj;
}
function layui_drive_brandModelMenu(){
	var nextNode = new Object();
	var nodeArr = new Array();
	var url = arguments[0];
	var selected = new Object();
	
	for(var i = 1; i< arguments.length;i++){
		if(arguments[i].length == 0) return;
		//上级菜单 = 下级菜单 + "^" + 下级菜单级别
		if(i > 1) nextNode[patamFilter(arguments[i - 1])] = patamFilter(arguments[i]) + "&" + i;
		
		//layui设定
		var elemId = arguments[i];
		if(arguments[i].indexOf("@") != -1){
			var temp = arguments[i].split("@");
			elemId = temp[0];
			selected[elemId] = temp[1];
		}
		$("#" + elemId).attr('lay-filter', elemId);
		nodeArr.push(elemId);
	}
	layui.use(['element', 'form', 'layedit', 'laydate', 'laypage'], function() {
		//监听提交
		var form = layui.form;
		if($("#" + nodeArr[0]).find("option").length == 1 
				&& $("#" + nodeArr[0]).find("option:eq(0)").val().length == 0){
			
			$("#" + nodeArr[0]).attr('lay-filter', nodeArr[0]);
			
			for(var i = 0;i < nodeArr.length;i++){
				var elemVal = selected[nodeArr[i - 1]];
				var pdata = new Object();
				pdata.name = nodeArr[i] + "&" + (i + 1);
				pdata.value = elemVal;
				roilandAjax(url,pdata,function(data){
					var html = "";
					for(var index in data.dropDown){
						html += "<option value=" + data.dropDown[index].key + (typeof selected[data.dropDownMenu] != "undefined" 
							&& selected[data.dropDownMenu] == data.dropDown[index].key ? " selected='selected'" : "") + ">" + data.dropDown[index].value +"</option>";
					}
					if(data.level != 0){
						for(var i = data.level;i< nodeArr.length;i++){
							$("#" + nodeArr[i]).find("option:not(:first)").remove();
						}
					}
					$("#" + data.dropDownMenu).find("option:not(:first)").remove();
					$("#" + data.dropDownMenu).find("option:first").after(html);
					
					//bootstrap-select 控件专用
					//form.render("select",data.dropDownMenu);
					form.render("select");
					
					if(typeof layuicallback == "function") layuicallback();
				});
			}
		}
		
		//添加选择事件
		for(var i in nodeArr){
			form.on("select(" + nodeArr[i] +")",function(pdata){
				var id = $(pdata.elem).attr("id");
				if(typeof nextNode[id] == "undefined") return false;
				//排除最后一个下拉选框
				if(nextNode[id] == nextNode[nextNode.length - 1]) return false;
				var data = new Object();
				data.name = nextNode[id];
				data.value = pdata.value;
				if($(this).find("option[default]:selected").length != 0) data.value = 0;
				roilandAjax(url,data,function(data){
					var html = "";
					for(var index in data.dropDown){
						html += "<option value=" + data.dropDown[index].key + ">" + data.dropDown[index].value +"</option>";
					}
					if(data.level != 0){
						for(var i = data.level;i< nodeArr.length;i++){
							$("#" + nodeArr[i]).find("option:not(:first)").remove();
						}
					}
					$("#" + data.dropDownMenu).find("option:not(:first)").remove();
					$("#" + data.dropDownMenu).find("option:first").after(html);
					
					//bootstrap-select 控件专用
					//form.render("select",data.dropDownMenu);
					form.render("select");
					
					if(typeof layuicallback == "function") layuicallback();
				});
			})
		}
	});
}
/**
 * ajax查询(async :true 异步 false 同步)
 * 
 * @param url
 * @param data
 * @param callbackFunction
 * @param async
 * @param datatype
 */
function roilandAjax(url,data,callbackFunction,async,datatype){
	if(typeof prefix != "undefined") url = prefix + url;
	if(typeof datatype == "undefined") datatype = "json";
	if(typeof async == "undefined") async = false;
	//$.tips('加载中...',600,'loading.gif');
	//showLoading();
	$.ajax({
		async:async,
		type:"post",  
		dataType:datatype,
        url:url + "?t=" + new Date().getTime(),
        data:data,
        success:function(data,status){
        	//hideLoading();
        	//if($.sys_validateAll(data)){
	        	//$.tips('加载中...',1,'loading.gif');
	        	if(typeof callbackFunction != "undefined")
	        		callbackFunction(data);
        	//}
        },
        error:function(data,status){
        	//hideLoading();
        	if(data.status == 401){ eval('(' + data.responseText + ')'); return;};
        	//$.tips('加载中...',1,'loading.gif');
        	alert("请求失败!");
        }
	});
}